home *** CD-ROM | disk | FTP | other *** search
-
- /* /// "header" */
- /* Main-Header File inserted by GenCodeC */
- /* Libraries */
- #include <libraries/mui.h>
- #include <libraries/gadtools.h> /* for BARLABEL in MenuItem */
-
- /* Prototypes */
- #ifdef __GNUC__
- #include <proto/muimaster.h>
- #include <proto/exec.h>
- #include <proto/alib.h>
- #include <proto/dos.h>
- #else
- #include <clib/muimaster_protos.h>
- #include <clib/exec_protos.h>
- #include <clib/alib_protos.h>
- #include <clib/dos_protos.h>
- #include <pragmas/muimaster_pragmas.h>
- #endif /* __GNUC__ */
-
- /* Ansi */
- #include <stdlib.h>
- #include <stdio.h>
-
- /* Increase stack size */
- LONG __stack=8192;
- /* GenCodeC header end */
-
- /* Include generated by GenCodeC */
- #include "GUI.h"
-
- /* --- own --- */
- #include <workbench/workbench.h>
- #include <workbench/startup.h>
- #include "dialtone.h"
- #include "listhooks.h"
- #include "_cat.h"
-
- /* ---------- */
-
- int PBchanged = 0;
- int StartIconified = 0;
-
- /* Declarations for libraries (inserted by GenCodeC) */
- struct Library * IntuitionBase=0;
- struct Library * MUIMasterBase=0;
- struct Library * LocaleBase=0;
- struct Library * IconBase=0;
-
- /* /// */
-
- /* /// "Arexx Hooks" */
- struct Hook RexxHook;
-
- APTR func_RexxHook(struct Hook *a0, APTR a2, APTR **a1)
- {
- /* a0->h_Data is a pointer to App
- a1 is an array of the Arexx parameters
- a1[0] is a pointer to the number string given to the arexx DIAL function */
- Dial(a0->h_Data, a1[0], 0);
-
- return NULL;
- }
- /* /// */
-
-
- /* /// "CopyList" */
- void CopyList(struct ObjApp *App)
- /* copies entries from phonebook list to dial list */
- {
- int i;
- LONG l, m;
- BOOL diff = FALSE;
- struct ListEntry *LE, *LE2;
-
- /* check if both lists are identical */
- get(App->LV_main, MUIA_List_Entries, &l);
- get(App->LV_set, MUIA_List_Entries, &m);
- if (l!=m) diff=TRUE;
-
- if (!diff && l>0)
- for (i=0;;i++)
- {
- DoMethod(App->LV_main,MUIM_List_GetEntry,i,&LE);
- DoMethod(App->LV_set,MUIM_List_GetEntry,i,&LE2);
- if (!LE) break;
-
- if (strcmp(LE->Name,LE2->Name)!=0) diff=TRUE;
- if (strcmp(LE->Number,LE2->Number)!=0) diff=TRUE;
- };
-
-
- if (diff) /* copy list, if lists are different */
- {
- set(App->LV_main,MUIA_List_Quiet,TRUE);
-
- /* remove all entries from dial-list */
- DoMethod(App->LV_main,MUIM_List_Clear);
-
- /* copy entries from phonebook-list */
- for (i=0;;i++)
- {
- DoMethod(App->LV_set,MUIM_List_GetEntry,i,&LE);
- if (!LE) break;
- DoMethod(App->LV_main,MUIM_List_InsertSingle,LE,MUIV_List_Insert_Bottom);
- }
-
- set(App->LV_main,MUIA_List_Quiet,FALSE);
- }
-
- /* activate the entry, that is active in phonebook-list */
- get(App->LV_set,MUIA_List_Active, &l);
- if (l<0) l=0;
- set(App->LV_main,MUIA_List_Active, l);
- }
- /* /// */
-
- /* /// "LoadPhoneBook" */
- int LoadPhoneBook(struct ObjApp *App)
- {
- int i;
- struct ListEntry LE;
- BPTR f;
- char *name;
- char *number;
- char *str;
-
- get(App->STR_PA_pbname, MUIA_String_Contents, &str);
-
- f=Open(str,MODE_OLDFILE);
- if (!f) {free(str); return FALSE; }
-
- str=malloc(128);
- str=FGets(f,str,128);
- if (strncmp(str,"Dial Phonebook",14)!=0)
- {
- free(str);
- return FALSE;
- };
- free(str);
-
- set(App->LV_set,MUIA_List_Quiet,TRUE);
- DoMethod(App->LV_set,MUIM_List_Clear);
-
- name=malloc(128);
- number=malloc(128);
-
- while (1)
- {
- name=FGets(f,name,63);
- number=FGets(f,number,63);
-
- if (!number) break;
-
- if (name[strlen(name)-1]=='\n') name[strlen(name)-1]=0;
- if (number[strlen(number)-1]=='\n') number[strlen(number)-1]=0;
-
- strcpy(LE.Name,name);
- strcpy(LE.Number,number);
-
- DoMethod(App->LV_set,MUIM_List_InsertSingle, &LE, MUIV_List_Insert_Bottom);
- }
-
- Close(f);
-
- free(name);
- free(number);
-
- set(App->LV_set,MUIA_List_Quiet,FALSE);
- set(App->LV_set,MUIA_List_Active,MUIV_List_Active_Top);
-
- CopyList(App);
- PBchanged=0;
-
- return TRUE;
- }
- /* /// */
-
- /* /// "SavePhoneBook" */
- int SavePhoneBook(struct ObjApp *App)
- {
- int i;
- BPTR f;
- char *str = malloc(128);
-
- get(App->STR_PA_pbname, MUIA_String_Contents, &str);
-
- f=Open(str,MODE_NEWFILE);
- free(str);
- if (!f) return FALSE;
-
- FPuts(f,"Dial Phonebook - do not edit this file\n");
-
- for (i=0; ;i++)
- {
- struct ListEntry *LE;
-
- DoMethod(App->LV_set,MUIM_List_GetEntry,i,&LE);
- if (!LE) break;
-
- FPuts(f,LE->Name); FPutC(f,'\n');
- FPuts(f,LE->Number); FPutC(f,'\n');
- }
-
- Close(f);
- PBchanged=0;
- return TRUE;
- }
- /* /// */
-
-
- /* /// "init" */
- /* Init() function */
- void init( void )
- {
- if (!(IntuitionBase = OpenLibrary("intuition.library",37)))
- {
- printf("Can't Open Intuition Library\n");
- exit(20);
- }
- if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
- {
- printf("Can't Open MUIMaster Library\n");
- CloseLibrary(IntuitionBase);
- exit(20);
- }
- if (!(IconBase = OpenLibrary("icon.library",0)))
- {
- printf("Can't Open Icon Library\n");
- }
- if (!(LocaleBase = OpenLibrary("locale.library",38)))
- {
- printf("Can't Open Locale Library\n");
- printf("Built-in Language will be used !!!\n");
- }
- OpenAppCatalog(NULL,NULL);
- }
- /* GenCodeC init() end */
- /* /// */
-
- /* /// "end" */
- /* End() function */
- void end( int err )
- {
- CloseAppCatalog();
- if (LocaleBase)
- CloseLibrary(LocaleBase);
- if (IconBase)
- CloseLibrary(IconBase);
- CloseLibrary(MUIMasterBase);
- CloseLibrary(IntuitionBase);
-
- exit(err);
- }
- /* GenCodeC end() end */
- /* /// */
-
- /* /// "ReadToolTypes" */
- ReadToolTypes(struct WBStartup *wbmsg)
- {
- struct WBArg *wbarg;
- int i;
-
- for (i=0, wbarg=wbmsg->sm_ArgList; i<wbmsg->sm_NumArgs; i++, wbarg++)
- {
- LONG olddir = -1;
- struct DiskObject *diskobj;
-
- /* if there's a directory lock for this wbarg, CD there */
- if((wbarg->wa_Lock)&&(*wbarg->wa_Name))
- olddir = CurrentDir(wbarg->wa_Lock);
-
- if((*wbarg->wa_Name) && (diskobj=GetDiskObject(wbarg->wa_Name)))
- {
- char **toolarray;
- char *s;
-
- toolarray = (char **)diskobj->do_ToolTypes;
-
- if(s=(char *)FindToolType(toolarray,"CX_POPUP"))
- if(MatchToolValue(s,"NO")) StartIconified=1;
-
- /* Free the diskobject we got */
- FreeDiskObject(diskobj);
- }
- if(olddir != -1) CurrentDir(olddir); /* CD back where we were */
- }
- }
- /* /// */
-
- /* /// "main" */
- /* Main Function inserted by GenCodeC */
- int main(int argc,char **argv)
- {
- struct ObjApp * App = NULL; /* Object */
- BOOL running = TRUE;
- ULONG signal;
- LONG b;
- struct MUI_Command commands[2] = { {"dial","NUMBER",1,&RexxHook},
- {0,0,0,0} };
-
- /* Program initialisation : generated by GenCodeC */
- init();
-
- /* from Workbench */
- if (IconBase && argc==0) ReadToolTypes((struct WBStartup*)argv);
-
- /* Create Object : generated by GenCodeC */
- if (!(App = CreateApp(StartIconified)))
- {
- printf("Can't Create App\n");
- end(20);
- }
-
- DoMethod(App->App,MUIM_Application_Load,MUIV_Application_Load_ENVARC);
-
- LoadPhoneBook(App);
- set(App->LV_set,MUIA_List_Active,MUIV_List_Active_Top);
- set(App->LV_main,MUIA_List_Active,MUIV_List_Active_Top);
- set(App->window,MUIA_Window_ActiveObject, App->LV_main);
-
- get(App->CH_system, MUIA_Selected, &b);
- if (!b) set(App->STR_system, MUIA_Disabled, TRUE);
-
- get(App->LV_set, MUIA_List_Entries, &b);
- if (b==0)
- {
- set(App->BT_Dial, MUIA_Disabled, TRUE);
- set(App->STR_Name, MUIA_Disabled, TRUE);
- set(App->STR_Number, MUIA_Disabled, TRUE);
- set(App->BT_Remove, MUIA_Disabled, TRUE);
- set(App->BT_Sort, MUIA_Disabled, TRUE);
- set(App->BT_Save, MUIA_Disabled, TRUE);
- set(App->LV_main, MUIA_Disabled, TRUE);
- set(App->LV_set, MUIA_Disabled, TRUE);
- }
-
- /* Install Arexx-Hook */
- InstallHook(&RexxHook, func_RexxHook, App);
- set(App->App,MUIA_Application_Commands,commands);
-
- while (running)
- {
- switch (DoMethod(App->App,MUIM_Application_Input,&signal))
- {
- case MEN_QUIT :
- case MUIV_Application_ReturnID_Quit:
- {
- get(App->App,MUIA_Application_ForceQuit,&b);
-
- if (PBchanged && !b)
- {
- if (MUI_Request(App->App,App->window,0,"Dial",
- GetDialString(MSG_Quit_BT),
- GetDialString(MSG_Quit))==1)
- running = FALSE;
- }
- else
- running=FALSE;
- }
- break;
-
- case MEN_ABOUT :
- {
- DoMethod(App->App,OM_ADDMEMBER, App->aboutwin);
- DoMethod(App->aboutwin,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
- App->App,2,MUIM_Application_ReturnID,ID_ABOUT_CLOSE);
- DoMethod(App->A_BT_OK,MUIM_Notify,MUIA_Pressed,FALSE,
- App->App,2,MUIM_Application_ReturnID,ID_ABOUT_CLOSE);
- set(App->aboutwin,MUIA_Window_Open, TRUE);
- }
- break;
-
- case ID_ABOUT_CLOSE :
- {
- set(App->aboutwin,MUIA_Window_Open, FALSE);
- DoMethod(App->App, OM_REMMEMBER, App->aboutwin);
- }
- break;
-
- case ID_ABOUT_IMAGECLICK : Dial(App,"0190331331",0); break;
-
- case MEN_ABOUTMUI :
- {
- if (!App->muiaboutwin)
- App->muiaboutwin = AboutmuiObject,
- MUIA_Window_RefWindow, App->window,
- MUIA_Aboutmui_Application, App->App,
- End;
-
- if (App->muiaboutwin) set(App->muiaboutwin,MUIA_Window_Open,TRUE);
- } break;
-
- case ID_Dial :
- {
- LONG i;
- struct ListEntry *LE;
-
- get(App->LV_main, MUIA_List_Active, &i);
- DoMethod(App->LV_main,MUIM_List_GetEntry,i,&LE);
-
- set(App->App,MUIA_Application_Sleep,TRUE);
- Dial(App,LE->Number,0);
- set(App->App,MUIA_Application_Sleep,FALSE);
- }
- break;
-
- case ID_ListClick :
- {
- LONG i, page;
- struct ListEntry *LE;
- struct Object *Obj;
-
- /* fill in Name and Number string gadgets,
- when user selects entry in listview */
- get(App->LV_set, MUIA_List_Active, &i);
- DoMethod(App->LV_set,MUIM_List_GetEntry,i,&LE);
- set(App->STR_Name, MUIA_String_Contents, LE->Name);
- set(App->STR_Number, MUIA_String_Contents, LE->Number);
-
- /* if there are no entries in list, disable some objects.
- enable them, if there are entries */
- get(App->LV_set, MUIA_List_Entries, &i);
- if (i==0)
- {
- set(App->BT_Dial, MUIA_Disabled, TRUE);
- set(App->STR_Name, MUIA_Disabled, TRUE);
- set(App->STR_Number, MUIA_Disabled, TRUE);
- set(App->BT_Remove, MUIA_Disabled, TRUE);
- set(App->BT_Sort, MUIA_Disabled, TRUE);
- set(App->BT_Save, MUIA_Disabled, TRUE);
- set(App->LV_main, MUIA_Disabled, TRUE);
- set(App->LV_set, MUIA_Disabled, TRUE);
- }
- else
- {
- set(App->BT_Dial, MUIA_Disabled, FALSE);
- set(App->STR_Name, MUIA_Disabled, FALSE);
- set(App->STR_Number, MUIA_Disabled, FALSE);
- set(App->BT_Remove, MUIA_Disabled, FALSE);
- set(App->BT_Sort, MUIA_Disabled, FALSE);
- set(App->BT_Save, MUIA_Disabled, FALSE);
- set(App->LV_main, MUIA_Disabled, FALSE);
- set(App->LV_set, MUIA_Disabled, FALSE);
- }
-
- get(App->GR_grp_0,MUIA_Group_ActivePage,&page);
- get(App->window, MUIA_Window_ActiveObject, &Obj);
-
- if (Obj!=App->STR_Name && Obj!=App->STR_Number && page==1)
- set(App->window, MUIA_Window_ActiveObject, App->STR_Name);
-
- }
- break;
-
- case ID_DialPage :
- {
- CopyList(App);
- /* make dial-list active object for keyboard input */
- set(App->window,MUIA_Window_ActiveObject, App->LV_main);
- }
- break;
-
- case ID_Name :
- {
- LONG i;
- struct ListEntry *LE;
- char *name;
-
- /* get selected ListEntry */
- get(App->LV_set, MUIA_List_Active, &i);
- DoMethod(App->LV_set,MUIM_List_GetEntry,i,&LE);
-
- if (!LE) break;
-
- get(App->STR_Name, MUIA_String_Contents, &name);
-
- if (strcmp(LE->Name,name)!=0)
- {
- /* change name */
- strcpy(LE->Name,name);
- /* redraw it */
- DoMethod(App->LV_set,MUIM_List_Redraw,MUIV_List_Redraw_Active);
-
- PBchanged=1;
- }
- }
- break;
-
- case ID_Number :
- {
- LONG i;
- struct ListEntry *LE;
- char *number;
-
- /* get selected ListEntry */
- get(App->LV_set, MUIA_List_Active, &i);
- DoMethod(App->LV_set,MUIM_List_GetEntry,i,&LE);
-
- if (!LE) break;
-
- get(App->STR_Number, MUIA_String_Contents, &number);
-
- if (strcmp(LE->Number,number)!=0)
- {
- /* change number */
- strcpy(LE->Number,number);
- /* redraw it */
- DoMethod(App->LV_set,MUIM_List_Redraw,MUIV_List_Redraw_Active);
-
- PBchanged=1;
- }
- }
- break;
-
- case ID_Add:
- {
- struct ListEntry LE;
-
- memset(&LE,0,sizeof(struct ListEntry));
- DoMethod(App->LV_set,MUIM_List_InsertSingle,&LE,MUIV_List_Insert_Bottom);
- set(App->LV_set,MUIA_List_Active,MUIV_List_Active_Bottom);
- set(App->window, MUIA_Window_ActiveObject, App->STR_Name);
- }
- break;
-
-
- case MEN_LOAD : case ID_LoadPB :
- {
- int b;
-
- if (PBchanged)
- {
- if (MUI_Request(App->App,App->window,0,"Dial",
- GetDialString(MSG_BT_ReallyLoad),
- GetDialString(MSG_ReallyLoad))==1)
- b=LoadPhoneBook(App);
- }
- else
- b=LoadPhoneBook(App);
-
- if (!b)
- MUI_Request(App->App,App->window,0,"Dial",
- GetDialString(MSG_BT_OK),
- GetDialString(MSG_NOTLOADED));
- }
- break;
- case MEN_SAVE : case ID_SavePB :
- {
- if (!SavePhoneBook(App))
- MUI_Request(App->App,App->window,0,"Dial",
- GetDialString(MSG_BT_OK),
- GetDialString(MSG_NOTSAVED));
- }
- break;
- case ID_PBchanged : PBchanged=1; break;
-
- case MEN_SETDEFAULT :
- {
- set(App->SL_Length, MUIA_Slider_Level,12);
- set(App->SL_Pause, MUIA_Slider_Level,6);
- }
- break;
-
- /* Insert your code between the "case" statement and comment "end of case ..." */
- /* End computing of IDCMP */
-
- default:
- break;
- }
- if (running && signal) Wait(signal);
- }
- DisposeApp(App);
- end(0);
- }
- /* /// */
-
-